<?php
/*
 * 订单中心
 */

namespace Common\Model;
use Common\Model\BaseModel;



class OrderModel extends BaseModel{

    const ORDER_STATUS_WEI  =   0;//未支付
    const ORDER_STATUS_PAY  =   1;//已支付


    const ORDER_TYPE_XU     =   1;//续费
    const ORDER_TYPE_PORT   =   2;//端口

    /*
     * 获取订单号
     */
    public function getOrderNo(){
        $order_no = 'O' . date('YmdHis',time()) . rand(1000,9999);
        return $order_no;
    }


    //生成订单
    public function add($data){
        $data['order_no'] = isset($data['order_no'])?$data['order_no']:$this->getOrderNo();
        $data['order_status'] = isset($data['order_status'])?$data['order_status']:$this::ORDER_STATUS_WEI;
        $data['ctime'] = isset($data['ctime'])?$data['ctime']:time();
        return M('order')->add($data);
    }

    //支付成功结束订单
    public function end($order_id){
        //更新订单状态
        $order_data = [];
        $order_data['order_id'] = $order_id;
        $order_data['order_status'] = $this::ORDER_STATUS_PAY;
        $order_data['pay_time'] = time();
        return M('order')->save($order_data);
    }

}